package com.tledu.zyf.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tledu.zyf.model.Group;

public class JstlELServlet extends HttpServlet {
	public void m1() {
	}

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 普通字符串
		request.setAttribute("hello", "helloword");

		// 单个对象
		Group group = new Group("飞虎队");
		request.setAttribute("group", group);

		// 数组
		String[] strArray = { "a", "b", "c" };
		request.setAttribute("strArr", strArray);

		// 集合
		List<Group> groups = new ArrayList<Group>();
		for (int i = 0; i < 5; i++) {
			groups.add(new Group("张三+" + i));
		}
		request.setAttribute("group", groups);

		// map
		Map map = new HashMap();
		map.put("k1", "v1");
		map.put("k2", "v2");
		request.setAttribute("map", map);

		// empty
		request.setAttribute("v2", "");
		request.setAttribute("v3", new ArrayList());
		request.setAttribute("v4", "12345");
		request.setAttribute("v5", null);

		request.getRequestDispatcher("/jstl_el.jsp").forward(request, response);
	}
}
